//
//  AppDelegate.m
//  07-UITabbarController
//
//  Created by dllo on 16/7/22.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    _window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    _window.backgroundColor = [UIColor whiteColor];
    [_window makeKeyAndVisible];
//    ViewController *vc = [[ViewController alloc] init];
//    _window.rootViewController = [[UINavigationController alloc] initWithRootViewController:vc];
    
    ViewController *vc1 = [[ViewController alloc] init];
    ViewController *vc2 = [[ViewController alloc] init];
    ViewController *vc3 = [[ViewController alloc] init];
    ViewController *vc4 = [[ViewController alloc] init];
    ViewController *vc5 = [[ViewController alloc] init];

    
    UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:vc1];
    
    vc1.view.backgroundColor = [UIColor redColor];
    vc2.view.backgroundColor = [UIColor greenColor];
    vc3.view.backgroundColor = [UIColor yellowColor];
    vc4.view.backgroundColor = [UIColor grayColor];
    vc5.view.backgroundColor = [UIColor blueColor];
    
//    viewcontrollers所有的被管理的视图控制器，都在这个数组中
//    可以通过setter方法的形式，赋值
//setviewcontrollers:animated
//    通过一个数组创建完成后，如果数组中的控制器没有设置tabbaritem，则显示一个空的tabbaritem
//    tabbaritem 根据自己需求创建对应的tabbaritem
//    ViewController的属性
//    因为每个视图控制器的tabbaritem都不一样，因此不能设为tabbarcontroller的属性
    
    
//    创建方式 initwithtabbarsystemitem:tag
//    initwithTitle: image: tag:
//initwithTitle: selectedImage: tag:根据自定义的图片创建，增添选中的图片
    
//    如果数组个数过多大于5，会把多余的内容，统一使用一种方式去管理数组个数最好不要大于5
    
//    tabbar高度49
//    bartintcolor bar背景颜色
    
    vc1.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:200];
    vc2.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"视频" image:nil tag:200];
    vc3.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"电影" image:nil tag:200];
    vc4.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"个人设置" image:nil tag:200];
    
    vc5.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"个人设置" image:nil tag:200];
    
    vc1.title = @"测试";
    
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
    
    
//    主要管理相同功能的视图控制器
    UITabBarController *tabbar = [[UITabBarController alloc] init];
    [tabbar setViewControllers:@[navigation,vc2,vc3,vc4,vc5]];
    _window.rootViewController = tabbar;
    
//    tabbar.tabBar.barTintColor = [UIColor greenColor];
    tabbar.tabBar.tintColor = [UIColor blackColor];//元素的颜色
    tabbar.tabBar.translucent = YES;//bar是否透明默认yes
    vc1.tabBarItem.badgeValue = @"未读";//角标
    
    [[UITabBar appearance] setTintColor:[UIColor yellowColor]];
    [[UITabBar appearance] setBarTintColor:[UIColor blackColor]];
    
//    self.title 或修改两个内容navigationitem.title和tabbaritem.title
//    navigationitem.title只修改navigationbar上的标题
    
    ViewController *vc = [[ViewController alloc] init];
    UINavigationController *navigation1 = [[UINavigationController alloc] initWithRootViewController:vc];
//    设置tabbaritem时给你要放进数组中的控制器去设置
    
    [tabbar setViewControllers:@[vc1]];
    _window.rootViewController = tabbar;
    vc1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"新闻" image:nil tag:0];
    
//    设置标题
    
    vc.title = @"News";
    vc1.navigationItem.title = @"news";
    
    
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
